﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DungeonGenerator.Tests
{
	using DungeonGenerator.Java;

	using FluentAssertions;

	using Microsoft.VisualStudio.TestTools.UnitTesting;
	[TestClass]
	public class DungeonMatchTests
	{
		[TestMethod]
		public void SimpleMatch1()
		{
			int seed = 1;
			int x = 30;
			int y = 25;
			int objects = 20;
			this.RunMatchTest(seed, x, y, objects);

		}

		//var longD= new Generator(80,25,40, 0, 75, new TestRandomizer(0));
		[TestMethod]
		public void LongMatch()
		{
			
			int x = 80;
			int y = 25;
			int objects = 40;
			for (int seed = 0; seed < 10; seed++)
			{
				this.RunMatchTest(seed, x, y, objects);
			}
		}
		public void RunMatchTest(int seed, int x, int y, int objects)
		{
			var expected = this.CreateTestJavaDungeon(seed, x, y, objects);
			var actual = this.CreateTestGenerator(seed, x, y, objects);


			for (int j = 0; j < y; j++)
				for (int i = 0; i < x; i++)
				{
					actual.Item2(i, j).ShouldBeEquivalentTo(expected.Item2(i, j));

				}
			actual.Item1.RandomsCount.ShouldBeEquivalentTo(expected.Item1.RandomsCount);
		}

		Tuple<TestRandomizer, Func<int, int, Tile>> CreateTestGenerator(int seed, int x, int y, int objects)
		{
			var rnd = new TestRandomizer(seed);
			var d = new Java.Generator(rnd, s => { });
			d.CreateDungeon(x, y, objects);
			Func<int, int, Tile> cellGetter = d.GetCellType;
			return Tuple.Create(rnd, cellGetter);
		}

		Tuple<TestRandomizer, Func<int, int, Tile>> CreateTestJavaDungeon(int seed, int x, int y, int objects)
		{
			var rnd = new TestRandomizer(seed);
			var d = new Java.JDungeon(rnd, s => { });
			d.CreateDungeon(x, y, objects);
			Func<int, int, Tile> cellGetter = d.GetCellType;
			return Tuple.Create(rnd, cellGetter);
		}

		[TestMethod]
		public void SimpleMatch20()
		{
			int x = 30;
			int y = 25;
			int objects = 20;
			for (int seed = 0; seed < 10; seed++)
			{
				this.RunMatchTest(seed, x, y, objects);	
			}
			
		}

		[TestMethod]
		public void SimpleMatchObjects10()
		{
			
			int x = 30;
			int y = 25;
			int objects = 10;
			for (int seed = 0; seed < 10; seed++)
			{
				this.RunMatchTest(seed, x, y, objects);
			}
		}
		[TestMethod]
		public void SimpleMatch0Objects30()
		{
		
			int x = 30;
			int y = 25;
			int objects = 30;
			for (int seed = 0; seed < 10; seed++)
			{
				this.RunMatchTest(seed, x, y, objects);
			}
		}
	}
}
